package com.fromfuture.xuhuidoc.android.commonresouce;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import app.auto.runner.base.SPrefUtil;
import app.auto.runner.base.utility.DataCleanManager;
import app.auto.runner.base.utility.ToastUtil;

/**
 * Author：何送军
 * creation time：2017/9/7    56711E529EED37B7E053AA0012AC8836
 **/
public class MyUrl {


    public static String G_WEBBASE_OUT = "http://sch.xmidware.com:8002/GZ/";
    public static String G_WEBBASE_TEST = "https://tsch.fromfuture.cn:7714/GZ/";
    public static String G_WEBBASE = G_WEBBASE_TEST;
    public static String DocTx = G_WEBBASE + "EAFormBlob.sp?guid=";
    //    public static String imgurl="https://sch.xmidware.com/chis/ROOT_CHIS/EAFormBlob.sp?guid=";
    public static String imgurl = "https://tsch.fromfuture.cn:1444/chis/ROOT_CHIS/EAFormBlob.sp?guid=";
    public static String imgurlpost = "ROOT_CHIS/EAFormBlob.sp?guid=";


    public static void change(Activity acty) {
        String G_WEBBASE = SPrefUtil.getValue("G_WEBBASE").toString();
        DataCleanManager.cleanApplicationData(acty);
        if (G_WEBBASE.equals("test")) {
            MyUrl.G_WEBBASE = G_WEBBASE_OUT;
            MyUrl.imgurl = G_WEBBASE_OUT + imgurlpost;
            SPrefUtil.putValue("G_WEBBASE", "out");
        } else if (G_WEBBASE.equals("out")) {
            MyUrl.G_WEBBASE = G_WEBBASE_TEST;
            MyUrl.imgurl = G_WEBBASE_TEST + imgurlpost;
            SPrefUtil.putValue("G_WEBBASE", "test");
        }

        ToastUtil.get(acty).toast(G_WEBBASE.equals("test") ? "切换到正式版" : "切换到测试版");
        Intent i = acty.getPackageManager().getLaunchIntentForPackage(acty.getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        acty.startActivity(i);
        android.os.Process.killProcess(android.os.Process.myPid());
    }

    public static void init(Context context) {
        SPrefUtil.iniContext(context.getApplicationContext());
        if (SPrefUtil.getValue("G_WEBBASE").toString().equals("")) {
            SPrefUtil.putValue("G_WEBBASE", "test");
            MyUrl.G_WEBBASE = G_WEBBASE_TEST;
            MyUrl.imgurl = G_WEBBASE_TEST + imgurlpost;
        }
    }
}
